package project.ekko.wow;

import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

import java.util.logging.Logger;


public class WOWAction {

    public interface User32 extends StdCallLibrary {

        User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.DEFAULT_OPTIONS);

        WinDef.HWND FindWindow(String lpClassName, String lpWindowName);

        boolean PostMessageA(WinDef.HWND hWnd, int Msg, int wParam, int lParam);

    }

    public static boolean sendMessage(int keyCode) {
        var hWnd = User32.INSTANCE.FindWindow(null, "魔兽世界");
        if (hWnd == null) {
            Logger.getGlobal().warning("Couldn't find a running World of Warcraft");
            return false;
        }
        User32.INSTANCE.PostMessageA(hWnd, WinUser.WM_KEYDOWN, keyCode, 0);
        User32.INSTANCE.PostMessageA(hWnd, WinUser.WM_KEYUP, keyCode,0);
        return true;
    }
}
